#ifndef __AT_CLIENT_H
#define __AT_CLIENT_H

#include "sys.h"

struct at_response
{
    /* response buffer */
    char *buf;
    /* the maximum response buffer size, it set by `at_create_resp()` function */
    uint32_t buf_size;
    /* the length of current response buffer */
    uint32_t buf_len;
    /* the number of setting response lines, it set by `at_create_resp()` function
     * == 0: the response data will auto return when received 'OK' or 'ERROR'
     * != 0: the response data will return when received setting lines number data */
    uint32_t line_num;
    /* the count of received response lines */
    uint32_t line_counts;
    /* the maximum response time */
    uint32_t timeout;
    /* the number of setting max response lines */
    uint32_t line_max;
    /* point to every line */
    char **line;
    uint32_t line_offset;
};
typedef struct at_response *at_response_t;

struct at_urc
{
    const char *cmd_prefix;
    const char *cmd_suffix;
    void (*func)(void *dev, const char *data, uint32_t size);
};
typedef struct at_urc *at_urc_t;

struct at_urc_table
{
    uint32_t urc_size;
    const struct at_urc *urc;
};
typedef struct at_urc_table *at_urc_table_t;


#define at_malloc(m)      pvPortMalloc(m)
#define at_free(m)        vPortFree(m)

extern at_response_t at_create_resp(uint32_t buf_size, uint32_t line_num, uint32_t line_max, uint32_t timeout);
extern void at_delete_resp(at_response_t resp);
extern char *at_resp_get_line(at_response_t resp,uint32_t resp_line);
extern char *at_resp_get_line_by_kw(at_response_t resp, const char *keyword);
extern void at_clinet_tick(uint32_t delayms);
extern int at_exec_cmd(at_response_t resp, const char *cmd_expr, ...);
extern int at_exec_cmdstr(at_response_t resp, char *cmdstr, uint16_t cmdlen);
extern void at_client_init(void *dev);
extern void at_client_flush(void);
extern int at_set_urc_table(const struct at_urc *urc_table, uint32_t table_sz);
extern void *at_get_dev(void);

#endif
